import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/entrys/rp/user_entity.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';
import 'package:xiongan_app_yy/widgets/comm/text_card_widget.dart';

//作业功能入口
class InfoListPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return InfoListPageState();
  }
}

class InfoListPageState extends State<InfoListPage> {
  List imageList = [
    "assets/images/info01.png",
    "assets/images/info02.png",
    "assets/images/info03.png",
    "assets/images/info04.png"
  ];
  List titleList = ["入库任务", "出库任务", "入库退货", "非预约审核结果"];
  List<Border> borderList = [
    Border(
        bottom: BorderSide(width: 1, color: Color(0xffdddddd)),
        right: BorderSide(width: 1, color: Color(0xffdddddd))),
    Border(bottom: BorderSide(width: 1, color: Color(0xffdddddd)))
  ];
  Border drawBorder;
  List routeList = [
    "/in_task",
    "/out_task",
    "/warehousing_returns",
    "/norderAuditResult"
  ];
  bool flag = true; //是否弹无权限toast
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: new AppBar(
          leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
          backgroundColor: Color(0XFF00A5F1),
          title: Text(
            "信息",
            style: TextStyle(fontSize: 18),
          ),
          elevation: 0,
          centerTitle: true,
        ),
        body: GridView.builder(
            itemCount: titleList.length,
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3, //横轴三个子widget
                childAspectRatio: 0.9 //宽高比为1时，子widget
                ),
            itemBuilder: (BuildContext context, int index) {
              if (index % 3 == 0) {
                drawBorder = borderList.elementAt(0);
              } else if (index % 3 == 1) {
                drawBorder = borderList.elementAt(0);
              } else if (index % 3 == 2) {
                drawBorder = borderList.elementAt(1);
              }
              ;
              return GestureDetector(
                child: Container(
                    decoration:
                        BoxDecoration(border: drawBorder, color: Colors.white),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Container(
                            padding: EdgeInsets.only(left: 38, right: 38),
                            child: Image.asset(imageList.elementAt(index),
                                fit: BoxFit.fill)),
                        Container(
                          child: Text(titleList.elementAt(index)),
                        )
                      ],
                    )),
                onTap: () {
                  for (int i = 0;
                      i < DataSingleton().Data.appModuleMenusList.length;
                      i++) {
                    UserAppmodulemenuslistMenutreedto bean = DataSingleton()
                        .Data
                        .appModuleMenusList
                        .elementAt(i)
                        .menuTreeDto;
                    for (int j = 0; j < bean.nezadaTreeList.length; j++) {
                      if (titleList.elementAt(index) ==
                          bean.nezadaTreeList.elementAt(j).nodeName) {
                        Navigator.pushNamed(
                            context, routeList.elementAt(index));
                        flag = false;
                        break;
                      }
                    }
                  }
                  if (flag) {
                    TostUtil.showToast("无权限");
                  }
                },
              );
            })

        /*ListView(
        children: <Widget>[
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/in_task");
              },
              title: "入库任务"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/out_task");
              },
              title: "出库任务"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "");
              },
              title: "入库退货"),
          TextCardWidget(
              onPressed: () {
                Navigator.pushNamed(context, "/norderAuditResult");
              },
              title: "非预约审核结果",
              border: Border.fromBorderSide(BorderSide.none)),
        ],
      ),*/
        );
  }
}
